<?php
class VideoUtils {

	public static function getVideoInfo($embed_code=null, $link=null){
		if($link){
			foreach(self::getLinkRegexps() as $video_type => $re){
				if(preg_match("/".$re."/i",$link,$matches)){
					return array('type' => $video_type, "code" => $matches[1]);
				}
			}
			
		}elseif($embed_code){
			foreach(self::getEmbedRegexps() as $video_type => $re){
				if(preg_match("/".$re."/i",$embed_code,$matches)){
					return array('type' => $video_type, "code" => $matches[1]);
				}
			}
		}
		throw new sfException('Unknown video link or embed code!');
	}
	
	
	public static function getVideoId($embed_code=null, $link=null){
		if(!($embed_code || $link)) return "";
	}
	
	private static function getEmbedRegexps(){
		return array(
			'youtube' => '\youtube\.com\/v\/([^\&]+)*',
			'vimeo' => 'moogaloop\.swf\?clip_id=([0-9]+)*',
			'dailymotion' => 'dailymotion\.com\/swf\/([^\&]+)*',
		    'seesmic' => 'seesmic.com.*value=\'video=([^\&]+)*'
		);	
		
	}
	
	private static function getLinkRegexps(){
		return array(
			'youtube' => 'v=([^\&]+)*',
			'vimeo' => 'vimeo.com\/([0-9]+)*',
			'dailymotion' => 'dailymotion\.com\/video\/([^\&]+)*',
		    'seesmic' => 'seesmic\.com\/videos?\/([^\/]+)*'
		);	
	}

	
}
?>